﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace AbpEntityFrameworkcore
{
   public  static class ConfigStaticHelper
    {


       private static  IConfiguration _configuration;
       public static string GetDbConnect()
        {
            // 获取当前程序集路径
            var assemblyLocation = Assembly.GetExecutingAssembly().Location;
            var assemblyDirectory = Path.GetDirectoryName(assemblyLocation);

            // 构建配置文件路径
            var configPath = Path.Combine(assemblyDirectory, "config.json");

            // 加载配置
            _configuration = new ConfigurationBuilder()
                .SetBasePath(assemblyDirectory)
                .AddJsonFile("config.json", optional: false, reloadOnChange: true)
                .Build();
            return _configuration["MySettings:DbConnect"];
        }
        public static string CustomIp()
        {
            // 获取当前程序集路径
            var assemblyLocation = Assembly.GetExecutingAssembly().Location;
            var assemblyDirectory = Path.GetDirectoryName(assemblyLocation);

            // 构建配置文件路径
            var configPath = Path.Combine(assemblyDirectory, "config.json");

            // 加载配置
            _configuration = new ConfigurationBuilder()
                .SetBasePath(assemblyDirectory)
                .AddJsonFile("config.json", optional: false, reloadOnChange: true)
                .Build();
            return _configuration["MySettings:CustomIp"];
        }

    }
}
